﻿package eu.liquify.ui {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.ui.Keyboard;
	public class TextBox extends LabeledItem implements IHasBindValue {
		protected var input:TextInput;
		
		public function TextBox(options:Object = null) {
			input = new TextInput();
			input.addEventListener(TextInput.TEXT_UPDATE, updateChange);
			
			super();
			width = 100;
			height = 18;
			applyOptions(options);
			
			item = input;
			addChild(input);
			
			resize();
		}
		
		public function get change():Function { return input.change; }
		public function set change(value:Function):void { input.change = value; }
		
		public function get bindValue():Object { return input.text; }
		public function set bindValue(v:Object):void { input.text = String(v); }
		
		public function get readonly():Boolean { return input.readonly; }
		public function set readonly(value:Boolean):void { input.readonly = value; }
		
		public function get centered():Boolean { return input.centered; }
		public function set centered(value:Boolean):void { input.centered = value; }
		
		override public function resize():void {
			super.resize();
			
			input.fixedSize = layoutType != PROPORTIONAL_SIZE || fixedSize;
			input.resize();
		}
		
		public function get text():String {
			return input.text;
		}
		public function set text(v:String):void {
			input.text = v;
			resize();
		}	
		public function get backgroundColor():uint {
			return input.backgroundColor;
		}
		public function set backgroundColor(v:uint):void {
			input.backgroundColor = v;
		}
		
		protected function updateChange(e:Event = null):void {
			e.stopImmediatePropagation();
			e.stopPropagation();
		}
		
	}
}